﻿using System.Windows.Forms;
using System;
using System.ComponentModel;
using UtfprLibrary.Windows.Forms.Exceptions;

namespace UtfprLibrary.Windows.Forms.Extensions {
    public static class CurrencyManagerExtensions {
        public static int AddNewUpdatingPosition(this CurrencyManager manager) {
            try {
                var bl = manager.List as IBindingList;
                manager.Position = bl.IndexOf(bl.AddNew());
                return manager.Position;
            } catch (Exception ex) {
                throw new UtfprWFCoreExtensionsException("", ex);
            }
        }

        public static int AddUpdatingPosition(this CurrencyManager manager, object entity) {
            try {
                var bl = manager.List as IBindingList;
                manager.Position = bl.Add(entity);
                return manager.Position;
            } catch (Exception ex) {
                throw new UtfprWFCoreExtensionsException("", ex);
            }
        }
    }
}
